<template>
    <div class="workstation-main">
        <div class="workstation-title">
            <span v-for="item in typeList" :key="item" @click="curNavType = item.id" :class="curNavType === item.id ? 'is-active' : ''"> {{ item.text }} </span>
        </div>
        <el-scrollbar class="workstation-scrollbar">
            <div class="workstation-content">
                <div class="workstation-nav" v-for="nav in navs" :key="nav.id">
                    <img :src="nav.icon" alt="">
                    <div class="workstation-right">
                        <span> {{nav.text}} </span>
                        <span> {{nav.tip}} </span>
                    </div>
                </div>
            </div>
        </el-scrollbar>
    </div>
</template>

<script>
import {
    reactive,
    toRefs,
    computed
} from "vue";

function generateRandomIcon() {  
    return `img (${Math.floor(Math.random() * 12)}).png`; 
}  
// 

export default {
    name: "WorkStationView",
    setup() {
        const state = reactive({
            navList: [
                {id: 0, type: 1, icon: require(`@/assets/${generateRandomIcon()}`), text: '行政管理', tip: '发布行政通知'},
                {id: 1, type: 2, icon: require('@/assets/img (8).png'), text: '行政管理', tip: '发布行政通知'},
                {id: 2, type: 3, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
                {id: 3, type: 4, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
                {id: 4, type: 5, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
                {id: 5, type: 6, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
                {id: 6, type: 3, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: ''},
                {id: 7, type: 2, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
                {id: 8, type: 1, icon: require('@/assets/haha.jpg'), text: '行政管理', tip: '发布行政通知'},
            ],
            typeList: [{id: 0, text: '全部应用'},
                {id: 1, text: '内部应用'},
                {id: 2, text: '营销相关'},
                {id: 3, text: '运营'},
                {id: 4, text: 'IT服务'},
                {id: 5, text: 'HR服务'},
                {id: 6, text: '其他'}
            ],
            curNavType: 0
        });

        const navs = computed(() =>{
            return state.navList.filter(nav => nav.type === state.curNavType || state.curNavType === 0)
        });

        for (let i = 0; i < 100; i++) {
            state.navList[i] = { id: i, type: Math.floor(Math.random() * 6) + 1, icon: require(`@/assets/${generateRandomIcon()}`), text: '行政管理', tip: '发布行政通知'};
        }

        return {
            ...toRefs(state),
            navs
        };
    },
};
</script>

<style lang="scss" scoped>
.workstation-main {
    background: #f6f6f7;
    height: 100%;
    width: 100%;
    -webkit-app-region: no-drag;

    .workstation-title {
        display: flex;
        padding-left: 5px;

        span {
            margin: 5px;
            color: #6d7176;
            font-size: small;
            padding: 5px 10px;
            border-radius: 5px;

            &:hover {
                background: #dedfe1;
            }

            &.is-active {
                background: #dedfe1;
                color: #000000;
            }
        }
    }

    .workstation-scrollbar {
        height: calc(100% - 37px);
        width: 100%;
        .workstation-content {
            display: grid;  
            grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));  
            grid-auto-rows: minmax(60px, auto);  
            gap: 10px; /* 调整子元素间的间距 */  
            padding: 10px 10px;
            
            .workstation-nav {
                background: #ffffff;
                display: flex;
                height: 60px;
                align-items: center; /* 子元素在交叉轴居中 */ 
                padding: 5px 10px;
                border-radius: 5px;
                border: 1px solid #dcdfe6;
                transition: all .3s ease-in-out;
                box-shadow: 0 12px 32px 4px #eeeef03d, 0 8px 20px #d2d5df7a;
                
                &:hover {
                    box-shadow: 0 12px 32px 4px #edeff53d, 0 8px 20px #6f71777a;
                    bottom: 6px;
                }

                span {
                    text-align: left;
                    font-size: medium;
                }

                span:last-child {
                    color: #9da0a3;
                    font-size: small;
                }

                img {
                    width: 40px;
                    height: 40px;
                    margin-right: 6px;
                }

                .workstation-right {
                    flex: 1;
                    display: flex;
                    flex-direction: column;
                }
            }
        }
    }

}
</style>

